#!/bin/env python

import time
import cv2
import numpy as np

pic_path = "../resource/pic/img_005.jpg"
windowName = "cnany"

cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 500 * 1, 500)

pic1 = cv2.imread(pic_path)
pic1_h, pic1_w, pic1_chn = pic1.shape

cv2.namedWindow("raw", cv2.WINDOW_NORMAL)
cv2.resizeWindow("raw", 500 * 1, 500)
cv2.imshow("raw", pic1)

def trackbarCallback(value):
    print(value)

new_min_value = 50
new_max_value = 60

old_min_value = new_min_value
old_max_value = new_max_value

cv2.createTrackbar('min', windowName, old_min_value, 100, trackbarCallback)
cv2.createTrackbar('max', windowName, old_max_value, 100, trackbarCallback)

# Canny算子
img = cv2.Canny(pic1, new_min_value, new_max_value)
cv2.imshow(windowName, img)

while True:
    if cv2.waitKey(1) == ord('q'):
        break

    new_min_value = cv2.getTrackbarPos('min', windowName)
    new_max_value = cv2.getTrackbarPos('max', windowName)

    if new_min_value != old_min_value:
        print("min_value:", new_min_value)
        old_min_value = new_min_value
        img = cv2.Canny(pic1, old_min_value, old_max_value)
        cv2.imshow(windowName, img)

    if new_max_value != old_max_value:
        print("max_value:", new_max_value)
        old_max_value = new_max_value
        img = cv2.Canny(pic1, old_min_value, old_max_value)
        cv2.imshow(windowName, img)



print('销毁窗口')
cv2.destroyAllWindows()


